function obs=newobstacle(nodes,varargin)
% newobstacle: create a new obstacle object
%
% SYNTAX:
%   obs = newobstacle(nodes,prop1,value1,...)
%   Return generated MADS.Obstacle object with specified nodes (Nx2 matrix) and properties
%   Type "newobstacle([])" to see available properties and their default values. 
%   You can use function DRAWOBSTACLE to draw the obstacle object.
%   
% See also NEWBBOUNDARY, DRAWOBSTACLE

%   Author: Hongbin Ma
%   Last updated: 2009-6-2 with MATLAB 6.5
%   Problems or suggestions? Email me: mathmhb[at]163.com

obs=struct('type','MADS.Obstacle',varargin{:});
obs.nodes=nodes;
obs=set_field(obs,'pos',zeros(1,2));
obs=set_field(obs,'ang',zeros(1,2));
obs=set_field(obs,'shape','polygon');
obs=set_field(obs,'size',1);
obs=set_field(obs,'color',[1 0 0]);
if isnumeric(nodes) & ~isempty(nodes),
    return;
end;
switch obs.shape,
case 'triangle'
    angles=rand(3,1)*pi*2-pi;
    angles=sort(angles);
case 'rect'
    angles=rand(4,1)*pi*2-pi;
    angles=sort(angles);
case 'polygon'
    n=floor(15*rand(1))+3;
    angles=rand(n,1)*pi*2-pi;
    angles=sort(angles);
case 'wall'
    a=rand(1)*pi*2-pi+[-0.05,0.05];
    angles=[a,-a(end:-1:1)]'+rand(1)*pi;
end;
n=length(angles);
obs.nodes=obs.size*[cos(angles),sin(angles)];
